<template>
	 <div class="add-node-btn-box" :class="{'complete-node': disabled}">
	 	<div class="add-node-btn" >
			<el-popover placement="right-start" v-model="visible" :width="270" trigger="click" :hide-after="0" :show-after="0">
				<template #reference>
					<el-button v-if="!disabled" type="primary" icon="el-icon-plus" circle></el-button>
				</template>
				<div class="add-node-popover-body">
					<ul>
						<li>
							<i style="color: #ff943e;" class="el-icon-user" @click="addType(1)"></i>
							<p>审批节点</p>
						</li>
						<li>
							<i style="color: #3296fa;" class="el-icon-s-promotion" @click="addType(2)"></i>
							<p>抄送节点</p>
						</li>
						<li>
							<i style="color: #15BC83;" class="el-icon-share" @click="addType(4)"></i>
							<p>条件分支</p>
						</li>
            <li>
            	<i style="color: #576A95;" class="el-icon-switch-button" @click="addType(6)"></i>
            	<p>结束节点</p>
            </li>
					</ul>
				</div>
			</el-popover>
	 	</div>
	 </div>
</template>

<script>
  import { color } from 'echarts'
import { generateSoleNodeId } from '../../../network/api.js'
	export default {
		props: {
			value: { type: Object, default: () => {} },
      disabled: {
        type: Boolean,
        default: false
      },
      parentNodeId: {
        type: String,
        default: ''
      },
      baseUrl: {
        type: String,
        default: ''
      },
      headers: {
        type: Object,
        default: () => {
          return {}
        }
      }
		},
		data() {
			return {
        visible: false
			}
		},
		mounted() {

		},
		methods: {
      getIdAction() {
        return new Promise((resolve, reject) => {
          generateSoleNodeId(this.baseUrl, this.headers).then(res => {
            resolve(res.data)
          })
        })
      },
      async getNodeId (node) {
        for (var i = 0; i < 2; i++) {
          const nodeId = await this.getIdAction()
          node.conditionNodes[i].nodeId = nodeId
        }
        this.$emit('input', node)
      },
			addType(type){
        console.log();
        generateSoleNodeId(this.baseUrl, this.headers).then(res=> {
          if (res.code === 200) {
            this.visible = false
            var node = {}
            if (type == 1) {
            	node = {
                parentNodeId: this.parentNodeId,
                nodeId: res.data,
            		nodeName: "审核人",
            		type: 1,			//节点类型
            		setType: 1,			//审核人类型
            		nodeUserList: [],	//审核人成员
            		nodeRoleList: [],	//审核角色
            		examineLevel: 1,	//指定主管层级
            		directorLevel: 1,	//自定义连续主管审批层级
            		selectMode: 1,		//发起人自选类型
            		termAuto: false,	//审批期限超时自动审批
            		term: 0,			//审批期限
            		termMode: 1,		//审批期限超时后执行类型
            		examineMode: 1,		//多人审批时审批方式
                rejectModel: {
                  rejectMode: 0, // 驳回模式
                  returnNodeId: '', // 驳回到指定节点
                },
            		directorMode: 0,	//连续主管审批方式
            		childNode: this.value,
                dealButtonNames: [], // 显示的操作名称
                dealButton: '',  // 操作 id
                dealButtons: [], // 操作 id
                color: '#FF943E', // 卡片颜色
                nodeDescription: ''
            	}
            }else if(type == 2){
            	node = {
                parentNodeId: this.parentNodeId,
                nodeId: res.data,
            		nodeName: "抄送人",
            		type: 2,
            		userSelectFlag: true,
            		nodeUserList: [],
            		childNode: this.value,
                dealButtonNames: [],
                dealButton: '',  // 操作 id
                dealButtons: [], // 操作 id
                color: '#3296FA', // 卡片颜色
                nodeDescription: ''
            	}

            }else if(type == 4){
            	node = {
                parentNodeId: this.parentNodeId,
                nodeId: res.data,
            		nodeName: "条件路由",
            		type: 4,
            		conditionNodes: [
            			{
            				nodeName: "条件1",
                    nodeDescription: '',
            				type: 3,
                    parentNodeId: res.data,
                    nodeId: '',
            				priorityLevel: 1,
            				conditionMode: 1,
            				conditionList: []
            			},
            			{
            				nodeName: "条件2",
                    nodeDescription: '',
            				type: 3,
                    parentNodeId: res.data,
                    nodeId: '',
            				priorityLevel: 2,
            				conditionMode: 1,
            				conditionList: []
            			}
            		],
            		childNode: this.value
            	}
              this.getNodeId(node)
            } else if (type == 6) {
              node = {
                nodeId: res.data,
                type: 6,
                color: '#576A95',
                nodeName: '结束',
                nodeDescription: ''
              }
            }
            if (type != 4) {
              this.$emit("input", node)
            }

          }
        })

			}
		}
	}
</script>

